PlayerFactory{

	*createSl{
		^RipplePlayer.new;
	}

	*createSlFromPath{|pathArg|
		var buffer, soundFilePath, sl, controlsDesc, isPreset, preset;
			
		soundFilePath = PresetUtils.getSoundFileFromPath(pathArg);
			
		sl = this.createSl;
				
		buffer = this.getBufferFromPath( soundFilePath );
		sl.setBuffer(buffer);
		
	
		^sl;
	}
	
	*getDataBuilder{
		^SequenceletDataBuilder;
	}
	
	*getBufferFromPath{|pathArg|
		var f;


		if(pathArg == nil){
			pathArg = "";	
		};
	
		try{
	
			f = SoundFile.new;
			f.openRead(pathArg);
			f.close;
		
		}{ |error|
			if(	
				error.species.name == 'PrimitiveFailedError',
				{
					InvalidSoundFileError("This does not appear to be a valid sound file: " + pathArg).throw
				},
				{error.throw}
			)
		};
		
		if(f.numFrames == 0){
			InvalidSoundFileError("This does not appear to be a valid sound file: " + pathArg).throw	
		};
	
		
		^MPBufferProxy.read( Server.local, pathArg, 0, f.numFrames );
	}
}

SamplePlayerFactory : PlayerFactory {}

NoSamplePlayerFactory : PlayerFactory{
	
	*createSlFromPath{
		^this.createSl;		
	}	
}

InvalidSoundFileError : Error{
	
}

